package com.lanou;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.bean.Account;
import com.lanou.bean.Student;
import com.lanou.mapper.AccuntMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import static org.apache.ibatis.ognl.DynamicSubscript.all;

public class MybatisLaunch {

    public static void main(String[] args) throws IOException {

        //Resources类是Mybatis是提供给开发者的工具类，专门用来加载类路径下资源
        InputStream in = Resources.getResourceAsStream("mybatis_conf.xml");

        //sqlSessionFactory对象是Mybatis中的工厂对象，整个工程只需要一个
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);


        SqlSession sqlSession = sqlSessionFactory.openSession(true);

        AccuntMapper accountMapper = sqlSession.getMapper(AccuntMapper.class);

        List<Account> all = accountMapper.queryAll();

        for (Account a:all) {
            System.out.println(a);
        }

        accountMapper.updateId(4,100);


        PageHelper.startPage(2,1);
        List<Account> all2 = accountMapper.queryAll();
        all2.forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(all2);
        System.out.println(pageInfo);


        Account account = accountMapper.queryT();
        System.out.println(account);

        List<Student> students = accountMapper.queryS();
       students.forEach(System.out::println);

        List<Account> blance = accountMapper.OrderBy("blance");
        blance.forEach(System.out::println);

    }

}







